//
//  LPMeetingActTableViewCell.m
//  GongXinDangJian
//
//  Created by 刘应平 on 2017/12/9.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "LPMeetingActTableViewCell.h"

@interface LPMeetingActTableViewCell ()
@property (nonatomic , strong) UIButton * deleteButton;
@end

@implementation LPMeetingActTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

/**  140  */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
    }
    return self;
}



#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.headLine];
    [self addSubview:self.meetAddress];
    [self addSubview:self.publishUnit];
    [self addSubview:self.meetTime];
    [self addSubview:self.endTime];
    [self addSubview:self.deleteImageView];
    [self addSubview:self.photoImageView];
    [self addSubview:self.applyButton];
    [self addSubview:self.bottomView];
    [self addSubview:self.deleteButton];
    
    self.headLine.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 80 * [UIScreen zj_screenWScale])
    .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
    .heightIs(1);
    
    
    self.meetAddress.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.headLine, 15 * [UIScreen zj_screenHScale])
    .heightIs(1);
    
    
    self.publishUnit.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.meetAddress, 10 * [UIScreen zj_screenHScale])
    .heightIs(1);
    
    self.meetTime.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.publishUnit, 10 * [UIScreen zj_screenHScale])
    .heightIs(1);
    
    self.endTime.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.meetTime, 10 * [UIScreen zj_screenHScale])
    .heightIs(1);
    
    self.deleteImageView.sd_layout
    .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(20 * [UIScreen zj_screenHScale]);
    
    self.deleteButton.sd_layout
    .rightSpaceToView(self, 0)
    .topSpaceToView(self, 0)
    .heightIs(40 * [UIScreen zj_screenHScale])
    .widthIs(45 * [UIScreen zj_screenHScale]);
    
    
    self.photoImageView.sd_layout
    .rightSpaceToView(self.deleteImageView, 10 * [UIScreen zj_screenWScale])
    .topSpaceToView(self, 12 * [UIScreen zj_screenHScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .widthIs(15 * [UIScreen zj_screenHScale]);
    
    self.applyButton.sd_layout
    .rightSpaceToView(self, 0 * [UIScreen zj_screenWScale])
    .bottomEqualToView(self)
    .heightIs(40 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith]);
    
    self.bottomView.sd_layout
    .rightSpaceToView(self, 0 * [UIScreen zj_screenWScale])
    .bottomEqualToView(self)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith]);
    
    
}



#pragma mark - 监听事件
- (void)tapImageView:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(LPMeetingActTableViewCellDeleteWithModel:row:)]) {
        [self.delegate LPMeetingActTableViewCellDeleteWithModel:self.model row:self.row];
    }
}

- (void)clickButton{
    if (self.delegate && [self.delegate respondsToSelector:@selector(LPMeetingActTableViewCellApplyWithModel:row:)]) {
        [self.delegate LPMeetingActTableViewCellApplyWithModel:self.model row:self.row];
    }
}

- (void)setModel:(LPMeetingActModel *)model{
    _model = model;
    self.headLine.text = model.TITLE;
    self.headLine.sd_layout.heightIs(model.TITLEHEIGHT);
    [self.headLine updateLayout];
    
    self.meetAddress.text = model.ADDRESSSTRING;
    self.meetAddress.sd_layout.heightIs(model.ADDRESSHEIGHT);
    [self.meetAddress updateLayout];
    
    self.publishUnit.text = model.PUBLISH_UNITSTRING;
    self.publishUnit.sd_layout.heightIs(model.PUBLISHUNITHEIGHT);
    [self.publishUnit updateLayout];
    
    self.meetTime.text = model.HY_START_TIMESTRING;
    self.meetTime.sd_layout.heightIs(model.HY_START_TIMEHEIGHT);
    [self.meetTime updateLayout];
    
   
    self.endTime.text = model.END_TIMESTRING;
    self.endTime.sd_layout.heightIs(model.END_TIMEHEIGHT);
    [self.endTime updateLayout];
    
   
    
    if ([model.IS_PAST integerValue] == 1) {
        self.deleteImageView.hidden = NO;
        self.deleteButton.hidden = NO;
        self.photoImageView.sd_layout.rightSpaceToView(self.deleteImageView, 10 * [UIScreen zj_screenWScale]);
        [self.photoImageView updateLayout];
        if ([model.RES_COUNT integerValue] != 0) {
            self.photoImageView.hidden = NO;
        }else{
            self.photoImageView.hidden = YES;
        }
    
        self.applyButton.backgroundColor = [UIColor lightGrayColor];
        [self.applyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.applyButton.userInteractionEnabled = NO;
        self.applyButton.alpha = 1;
        
        
    }else{
        self.deleteImageView.hidden = YES;
        self.deleteButton.hidden = YES;
        self.photoImageView.sd_layout.rightSpaceToView(self, 15 * [UIScreen zj_screenWScale]);
        [self.photoImageView updateLayout];
        if ([model.RES_COUNT integerValue] != 0) {
            self.photoImageView.hidden = NO;
        }else{
            self.photoImageView.hidden = YES;
        }
        
        self.applyButton.backgroundColor = [UIColor zj_colorWithHexString:@"ffb0b0"];
        [self.applyButton setTitleColor:[UIColor themeColor] forState:UIControlStateNormal];
        self.applyButton.userInteractionEnabled = YES;
    }
    
    if ([self.IS_ENROLL integerValue] == 0) {
        self.endTime.hidden = NO;
        self.applyButton.hidden = NO;
    }else{
        self.endTime.hidden = YES;
        self.applyButton.hidden = YES;
    }
    
    
}


#pragma mark - getter
- (UILabel *)headLine{
    if (!_headLine) {
        _headLine = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
             label.numberOfLines = 0;
            label;
        });
    }
    return _headLine;
}


- (UILabel *)meetAddress{
    if (!_meetAddress) {
        _meetAddress = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label.numberOfLines = 0;
            label;
        });
    }
    return _meetAddress;
}

- (UILabel *)publishUnit{
    if (!_publishUnit) {
        _publishUnit = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label.numberOfLines = 0;
            label;
        });
    }
    return _publishUnit;
}


- (UILabel *)meetTime{
    if (!_meetTime) {
        _meetTime = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label.numberOfLines = 0;
            label;
        });
    }
    return _meetTime;
}


- (UILabel *)endTime{
    if (!_endTime) {
        _endTime = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label.numberOfLines = 0;
            label;
        });
    }
    return _endTime;
}

- (UIImageView *)deleteImageView{
    if (_deleteImageView == nil) {
        _deleteImageView = [UIImageView new];
        _deleteImageView.userInteractionEnabled = YES;
        _deleteImageView.contentMode = UIViewContentModeCenter;
        _deleteImageView.image = [UIImage imageNamed:@"message_del"];
    }
    return _deleteImageView;
}


-(UIButton *)deleteButton
{
    if (!_deleteButton) {
        _deleteButton = [ToolClass createButtonWithFrame:CGRectMake(1, 1, 1, 1) text:@"" textColor:[UIColor whiteColor] imageName:@"" font:15];
        [_deleteButton addTarget:self action:@selector(tapImageView:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

- (UIImageView *)photoImageView{
    if (_photoImageView == nil) {
        _photoImageView = [UIImageView new];
        _photoImageView.contentMode = UIViewContentModeCenter;
        _photoImageView.image = [UIImage imageNamed:@"icon_appendix"];
    }
    return _photoImageView;
}

- (UIButton *)applyButton{
    if (!_applyButton) {
        _applyButton = ({
            UIButton *button = [UIButton new];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.titleLabel.font = LYPFONT(18);
            [button setTitle:@"报名" forState:UIControlStateNormal];
            button;
            
        });
    }
    return _applyButton;
}


-(UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _bottomView.backgroundColor = [UIColor themeGrayColor];
    }
    return _bottomView;
}


@end
